package com.superb.common.database.interceptor;

import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;

import java.util.Set;

/**
 * 租户插件-删除拦截
 * @Author: ajie
 * @CreateTime: 2024-05-08 15:52
 */
@Slf4j
@AllArgsConstructor
public class SuperbDelInnerInterceptor implements TenantLineHandler {

    private final Set<String> ignoreDelTable;

    /**
     * 删除值0
     * @return
     */
    @Override
    public Expression getTenantId() {
        return new LongValue(0);
    }

    /**
     * 删除字段
     * @return
     */
    @Override
    public String getTenantIdColumn() {
        return "del";
    }

    /**
     * 根据nacos根配置中的删除拦截表排除删除条件
     * @param tableName
     * @return
     */
    @Override
    public boolean ignoreTable(String tableName) {
        return ignoreDelTable.stream().anyMatch(table -> table.equals(tableName));
    }
}
